{include file="public/header"}
<body>
	<div class="sectionY">
		<a href="{:url('Paytype/index')}">
			<img src="__PUBLIC__/home/images/a2_1.png" alt="" class="a1">
		</a>
		<p class="p1">绑定银行卡支付</p>
	</div>
	<div class="kong1"></div>
	<div class="res_section1">
		<form class='form_binding'  >
			<div class="all_1">
				<div class="f1">
					<span class="s1 ">开户名：</span>
					<input type="text" class="input1" name='realname' value="{$userinfo.realname}" placeholder="开户姓名">
				</div>
				<div class="f1">
					<span class="s1 " style="position: relative;top:-5px;">开户行：</span>
					<div class="arr">
						<select name="banktypename" id="banktypename">
							{volist name='catelist' id='cv'}
                			<option value='{$cv.bank_name}' {if condition="$cv['bank_name'] eq $userinfo['banktypename']"} selected='selected' {/if} >{$cv.bank_name}</option>
                			{/volist}
						</select>
					</div>
					<img src="__PUBLIC__/home/images/a23_1.png" alt="" class="im_y">
				</div>
				<div class="f1">
					<span class="s1 ">开户支行：</span>
					<input type="text" class="input1" name='bankname' placeholder="开户支行" value="{$userinfo.bankname}" >
				</div>
				<div class="f1">
					<span class="s1 ">银行卡号：</span>
					<input type="text" class="input1" name='bankcard' placeholder="银行卡号" value="{$userinfo.bankcard}">
				</div>
                <div class="f1">
    				<span class="s1 ">交易密码：</span>
    				<input type="password" name='pwd' class="input1" placeholder="交易密码" />
    			</div>
    			<div class="sub">
    				<input type="button" value="确认提交" onclick='return check_repwd();' />
    			</div>
			</div>
		</form>
	</div>
</body>


</html>

<script>
function check_repwd(){
    var name= $('input[name=realname]').val();
    var user= $('#banktypename').val();
    var files = $('input[name=bankname]').val();
    var img_url=$('input[name=bankcard]').val();
    var repwd  = $('input[name=pwd]').val();
    if(name==''){
        layer.alert('请输入开户名！');return false;
    }
    var nameReg = /^[\u4E00-\u9FA5]{2,4}$/;
    if(!nameReg.test(name)){
        layer.alert('开户姓名格式错误，请检查！',{icon: 2,shade:0.8,title:"错误提示:"});return false;
    }
    if(user==''){
        layer.alert('请选择开户行！');return false;
    }
    if(files==''){
        layer.alert('请填写开户支行！');return false;
    }
    if(repwd==''){
        layer.alert('请填写交易密码！');return false;
    }
    var cardcodepartten = /^(\d{16}|\d{17}|\d{18}|\d{19})$/;
    if(!cardcodepartten.test(img_url)){
        layer.alert('银行卡号格式错误，请检查！',{icon: 2,shade:0.8,title:"错误提示:"});return false;
    }
    if(img_url==''){
        layer.alert('请填写银行卡号！');return false;
    }
    /*ajax检测交易密码*/
    $.ajax({
        type: 'POST',
        url: "{:url('Paytype/check_repwd')}",
        dataType: "html",
        data: "code="+repwd,
        success:function(responsestr){
            if(responsestr==1){
                $.ajax({
                    type: 'POST',
                    url: "{:url('Paytype/docard')}",
                    dataType: "json",
                    data: {realname:name,banktypename:user,bankname:files,bankcard:img_url},
                    success:function(re){
                        var obj=re;
                        if(obj.s==1){
                            layer.msg(obj.msg,{shade:0.6,time:1000,end:function(){
                                    window.location.href=window.location.href;
                                }});
                        }else{
                            layer.alert(obj.msg,{shade:0.2});return false;
                        }
                    },
                    error:function(){
                        layer.alert('系统繁忙，请稍后再试！',{shade:0.2});
                    }
                });
            }else{
                layer.alert(responsestr,{shade:0.2});
            }
        },
        error:function(){
            layer.alert('系统繁忙，请稍后再试！',{shade:0.2});
        }
    });
}
</script>
